/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.gui;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

public class AnalysisIcon extends ImageIcon implements Comparable {
    private int sortingIndex;
    private String toolTipText;

    AnalysisIcon(Image image, String toolTipText_, int sortingIndex_) {
        super(image);
        toolTipText = toolTipText_;
        sortingIndex = sortingIndex_;
    }

    public String getToolTipText() {
        return toolTipText;
    }

    public int compareTo(Object o) {
        return new Integer(sortingIndex).compareTo(new Integer(((AnalysisIcon)o).sortingIndex));
    }

    static AnalysisIcon SUCCESSFUL_RUN_ICON =
	new AnalysisIcon(new SquareImage(10, Color.green),
			 "Instance found",
			 1);
    static AnalysisIcon FAILED_RUN_ICON =
	new AnalysisIcon(new CircleImage(10, Color.red),
			 "No instance found",
			 2);
    static AnalysisIcon IN_PROGRESS_RUN_ICON =
	new AnalysisIcon(new CircleImage(10, Color.yellow),
			 "Searching for instance",
			 3);
    static AnalysisIcon SUCCESSFUL_ASSERTION_ICON =
	new AnalysisIcon(new SquareImage(10, Color.green),
			 "No counterexample found",
			 5);
    static AnalysisIcon FAILED_ASSERTION_ICON =
	new AnalysisIcon(new SquareImage(10, Color.red),
			 "Counterexample found",
			 6);
    static AnalysisIcon IN_PROGRESS_ASSERTION_ICON =
	new AnalysisIcon(new SquareImage(10, Color.yellow),
			 "Searching for counterexample",
			 7);
    static AnalysisIcon META_INSTANCE_ICON =
	new AnalysisIcon(new SquareImage(10, Color.blue),
			 "Metamodel",
			 9);

    static AnalysisIcon UNSAT_CORE_ICON = 
	new AnalysisIcon(new SquareImage(10, Color.pink),
			 "UnsatCore",
			 10);
}

class CircleImage extends BufferedImage {
    CircleImage(int size, Color color) {
	super(size, size, TYPE_INT_ARGB);

	Graphics2D g = createGraphics();
	//g.setColor(Color.white);
	//g.fillRect(0, 0, size, size);
	//g.clearRect(0, 0, size, size);
	g.setClip(0, 0, size, size);
	g.setColor(color);
	g.fillOval(0, 0, size - 1, size - 1);
    }
}

class SquareImage extends BufferedImage {
    SquareImage(int size, Color color) {
	super(size, size, TYPE_INT_RGB);

	Graphics2D g = createGraphics();
	g.setColor(color);
	g.fillRect(0, 0, size, size);
    }
}

